﻿#if NETSTANDARD2_0
using Microsoft.Extensions.Configuration;
using System;
using System.IO;

namespace RabbitMQExtension
{
    public partial class MQHelper : IDisposable
    {
        /// <summary>
        /// 无参构造函数，从配置文件，按照约定读取数据
        /// 从appsettings MQ 节点中读取 配置节点
        /// Host,UserName,Password
        /// </summary>
        public MQHelper()
        {
            var builder = new ConfigurationBuilder()
              .SetBasePath(Directory.GetCurrentDirectory())
              .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
            var config = builder.Build().GetSection("MQ").Get<MQConfig>();
            if (string.IsNullOrEmpty(config.Host))
                throw new ArgumentNullException(nameof(config.Host));
            if (string.IsNullOrEmpty(config.UserName))
                throw new ArgumentNullException(nameof(config.UserName));
            if (string.IsNullOrEmpty(config.Password))
                throw new ArgumentNullException(nameof(config.Password));
            Open(config);
        }
    }
}
#endif